package com.cw.base.common.dispatch.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

import com.cw.base.common.dispatch.exec.AsyncExecMessageListening;
import com.cw.base.common.dispatch.task.facade.TaskFacade;
import com.cw.base.common.dispatch.event.EventWrapper;
import com.cw.base.common.dispatch.listening.MessageListening;
import com.cw.base.common.dispatch.obtain.ObtainTask;
import com.cw.base.common.dispatch.queue.Queue;
import com.cw.base.common.dispatch.queue.TaskQueue;
import com.cw.base.common.dispatch.task.facade.ref.CompensateTaskFacade;

/**
 * @author chenw
 * @version $$Id: DispatchConfiguration.java, v 0.1 2018/11/26 2:56 PM chenw Exp $$
 */
@Configuration
@EnableConfigurationProperties(DispatchProperties.class)
public class DispatchConfiguration {

    @Autowired
    private DispatchProperties dispatchProperties;

    @Bean
    public TaskFacade taskFacade() {
        return new CompensateTaskFacade();
    }

    @Bean
    public ObtainTask obtainTask() {
        return new ObtainTask();
    }

    @Bean
    public MessageListening asyncExecMessageListening() {
        return new AsyncExecMessageListening();
    }

    @Bean
    @Lazy
    public Queue taskQueue() {
        return new TaskQueue(dispatchProperties.getTaskQueueSize(), dispatchProperties.getFileName());
    }

    @Bean
    public EventWrapper eventWrapper() {
        return new EventWrapper(asyncExecMessageListening());
    }
}
